package org.grow.loginto.filter;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @Author: xwg
 * @CreateDate: 21-6-4
 */
@Service
public class TestFilter extends OncePerRequestFilter {


    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        System.out.println(this.getClass()+" => "+httpServletResponse.getCharacterEncoding());
        httpServletResponse.setCharacterEncoding(StandardCharsets.UTF_8.name());
        filterChain.doFilter(httpServletRequest,httpServletResponse);
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();


        System.out.println(this.getClass()+" ==>> "+principal);
    }
}
